<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
"Mathematician clock" by Stephane Tsacas
stephane.tsacas+eleeno@gmail.com
-->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>Mathematician time</title>
<style type="text/css"><!--
.d {
  border-bottom: solid 1px #0000FF;
  text-align: center;
}

.a {
  text-align: center;
}
--></style>
<script type="text/javascript"><!--
// Set to something for debugging.
var debug = 0;

// Wrapper to new Date() so you can set the time manually when debugging.
function currentTime()
{
  var timeNow;

  if (debug)
    {
      timeNow = new Date(2009, 4, 1, 11, 33, 12); // Set the time as you want (3 last args).
    }
  else
    {
      timeNow = new Date();
    }
  return timeNow;
}

var hoursUp;
var hoursDown;
var minutesUp;
var minutesDown;
var secondsUp;
var secondsDown;

function cacheObjects()
{
  hoursUp = document.getElementById("hoursUp");
  hoursDown = document.getElementById("hoursDown");
  minutesUp = document.getElementById("minutesUp");
  minutesDown = document.getElementById("minutesDown");
  secondsUp = document.getElementById("secondsUp");
  secondsDown = document.getElementById("secondsDown");
}


var inited = 0;
// Main function, does it all. Called every second.
function blinkSomething()
{
  var timeNow = currentTime();
  var hours = timeNow.getHours();
  var minutes = timeNow.getMinutes();
  var seconds = timeNow.getSeconds();

  with (Math)
  {
    var hoursNominator;
    var hoursDenominator;
    var minutesNominator;
    var minutesDenominator;
    var secondNominator;
    var secondsDenominator;
    var x, y;
    var factor = 20000;

    x = round(random() * factor);
    y = (hours == 0) ? x : floor(x / hours);
    hoursNominator = (x & 1 == 1)   ? hours * x : y * hours;
    hoursDenominator = (x & 1 == 1) ?         x : y;

    x = round(random() * factor);
    y = (minutes == 0) ? x : floor(x / minutes);
    minutesNominator = (x & 1 == 1)   ? minutes * x : y * minutes;
    minutesDenominator = (x & 1 == 1) ?           x : y;

    x = round(random() * factor);
    y = (seconds == 0) ? x : floor(x / seconds);
    secondsNominator = (x & 1 == 1)   ? seconds * x : y * seconds;
    secondsDenominator = (x & 1 == 1) ?           x : y;
  }

  if (inited == 0)
    {
      hoursUp.innerHTML = hoursNominator;
      hoursDown.innerHTML = hoursDenominator;
      minutesUp.innerHTML = minutesNominator;
      minutesDown.innerHTML = minutesDenominator;
      inited = 1;
    }
  if (seconds == 0)
    {
      hoursUp.innerHTML = hoursNominator;
      hoursDown.innerHTML = hoursDenominator;
      minutesUp.innerHTML = minutesNominator;
      minutesDown.innerHTML = minutesDenominator;
    }
  secondsUp.innerHTML = secondsNominator;
  secondsDown.innerHTML = secondsDenominator;
}


//-->
</script>
  </head>

<body onload="cacheObjects(); setInterval('blinkSomething()', 1000)" >
  <div id="clockDisplay" style='font:14pt "Courier New" "Courier" "Monaco"'>
    <table>
      <tr>
	<td>
	<table width="80">
	  <tr bottom>
	    <td class="d" id='hoursUp'></td>
	  </tr>
	  <tr>
	    <td class="a" id='hoursDown'></td>
	  </tr>
	</table>
	</td>
	<td>
	<table width="80">
	  <tr>
	    <td class="d" id='minutesUp'></td>
	  </tr>
	  <tr>
	    <td class="a" id='minutesDown'></td>
	  </tr>
	</table>
	</td>
	<td>
	<table width="80">
	  <tr>
	    <td class="d" id='secondsUp'></td>
	  </tr>
	  <tr>
	    <td class="a" id='secondsDown'></td>
	  </tr>
	</table>
	</td>
      </tr>
      </table>
  </div>
</body>
</html>
